using System;

namespace CodingWheels.DataTypes.Core
{
	public abstract class Unit : IEquatable<Unit>
	{
		public string Name
		{
			get;
			protected set;
		}

		public string Symbol
		{
			get;
			protected set;
		}

		protected Unit(string name, string symbol)
		{
			Name = name;
			Symbol = symbol;
		}

		public bool Equals(Unit other)
		{
			if(ReferenceEquals(null, other))
			{
				return false;
			}

			return ReferenceEquals(this, other) || (Name == other.Name && Symbol == other.Symbol && GetType() == other.GetType());
		}

		public override bool Equals(object obj)
		{
			if(ReferenceEquals(null, obj))
			{
				return false;
			}
			
			return obj.GetType() == typeof(Unit) && Equals((Unit)obj);
		}

		public override int GetHashCode()
		{
			return Name.GetHashCode() * 123 + Symbol.GetHashCode() * 321 + GetType().GetHashCode() * 456;
		}

		public override string ToString()
		{
			return Name;
		}
	}
}